﻿@model DNA.Mvc.Management.SmtpModel
@{
    ViewBag.Title = "Stmp";
    Layout = "~/Views/Shared/_Dashboard.cshtml";
}
@UIHelper.ImageTitle(Html.Global("RES_SMTPSETTINGS"), Html.Global("SMTP_Settings_Tips"), "~/content/images/icon_smtp_48.png")
@using (Html.BeginForm())
{
    
    @UIHelper.SectionHeader(Html.Global("RES_COMMON"))
    <table class="d-field-table">
        <tr>
            <td>
                <h3 class="d-field-title">
                    <label for="Web_SMTPHost">
                        @Html.Global("RES_SMTPSERVER")</label></h3>
                <div class="d-field-description">
                    @Html.Global("SMTP_SRV_Tips")
                </div>
            </td>
            <td style="vertical-align: middle;">
                @Ajax.DnaFor().TextBox(m => m.Host).Width(300).GetHtml()
            </td>
        </tr>
        <tr>
            <td>
                <h3 class="d-field-title">
                    <label for="Web_SMTPPost">
                        @Html.Global("RES_SMTP_PORT")</label></h3>
                <div class="d-field-description">
                    @Html.Global("SMTP_PORT_Tips")
                </div>
            </td>
            <td style="vertical-align: middle;">
                @Ajax.DnaFor().TextBox(m => m.Port).Width(75).NumericOnly().Value(Model.Port == 0 ? 25 : Model.Port).GetHtml()
            </td>
        </tr>
        @* <tr>
        <td valign="top">
            <h3 class="d-field-title">
                <label for="Web_SiteMailAccount">
                    @Html.Global("RES_ADMINEMAIL")
                </label>
            </h3>
            <div class="d-field-description">
                @Html.Global("SiteSettings_SMTP_AdminEmail_Tips")
            </div>
        </td>
               <td valign="middle">
            @Ajax.Dna().TextBox("Web.SiteMailAccount").Width(300).Value(Model.).GetHtml()
        </td>
    </tr>*@
        <tr>
            <td colspan="2">
                @( Ajax.Dna().Checkbox("SmtpModel.DefaultCredentials", Html.Global("RES_USEDDEFAULTCREDENTIALS"),
                       Model.DefaultCredentials,
                           Url.Content("~/content/images/icon_accept_16.png"),
                           Url.Content("~/content/images/icon_block_16.png"))
                           .GetHtml()
                    )
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @( Ajax.Dna().Checkbox("SmtpModel.EnableSsl", "EnableSsl", Model.EnableSsl,
                           Url.Content("~/content/images/icon_accept_16.png"),
                           Url.Content("~/content/images/icon_block_16.png"))
                           .GetHtml()
                    )
            </td>
        </tr>
        <tr>
            <td>
                <h3 class="d-field-title">
                    <label for="Web_SMTPUserName">
                        @Html.Global("RES_SMTP_USERNAME")</label></h3>
                <div class="d-field-description">
                    @Html.Global("SMTP_UserName_Tips")</div>
            </td>
            <td style="width: 550px;">
                @Ajax.DnaFor().TextBox(m => m.UserName).Width(300).GetHtml()
            </td>
        </tr>
        <tr>
            <td>
                <h3 class="d-field-title">
                    <label for="Web_SMTPPassword">
                        @Html.Global("RES_SMTP_PASSWORD")</label></h3>
                <div class="d-field-description">
                    @Html.Global("SMTP_PWD_Tips")</div>
            </td>
            <td style="vertical-align: middle">
                @Ajax.DnaFor().TextBox(m => m.Password).Password().Width(300).GetHtml()
            </td>
        </tr>
    </table>
    @UIHelper.SectionHeader(Html.Global("RES_ACCOUNTS"))
    <table class="d-field-table">
        <tr>
            <td style="vertical-align: top;">
                <h3 class="d-field-title">
                    <label for="Web_SMTPUserName">
                        @Html.Global("SMTP_Sender_Account")</label></h3>
                <div class="d-field-description">
                     @Html.Global("SMTP_Sender_Account_Tips")
                </div>
            </td>
            <td>
                @Ajax.DnaFor().TextBox(m => m.From).Width(300).GetHtml()
            </td>
        </tr>
        <tr>
            <td>
                <h3 class="d-field-title">
                    <label for="Web_SMTPPassword">
                        @Html.Global("SMTP_Critical_Account")
                    </label>
                </h3>
                <div class="d-field-description">
                     @Html.Global("SMTP_Critical_Account_Tips")
                </div>
            </td>
            <td style="width: 550px;">
                @Ajax.DnaFor().TextBox(m => m.CriticalMail).Width(300).GetHtml()
            </td>
        </tr>
    </table>
    <hr />
    <div id="d_test_info" style="display: none; padding: 10px;" class="ui-state-highlight">
        <span class="d-loader"></span><span id="d_info">@Html.Global("SMTP_Sending_Test")</span>
    </div>
    <div id="d_buttons" style="padding: 10px; text-align: center;">
        @Ajax.Dna().Button().LocText("RES_TEST").Click("_testSMTP();").GetHtml()
        @Ajax.Dna().Button().LocText("RES_SAVE").Submit().ImageIcons(Url.Content("~/content/images/icon_save.gif")).GetHtml()
        @Ajax.Dna().Link(Html.Global("RES_HELP"), Url.Help(10), Url.Content("~/content/images/help.png")).Options(opts => { opts.Target = "_blank"; }).GetHtml()
    </div>
}
<script type="text/javascript">
    function _testSMTP() {
        $("#d_buttons").hide();
        $("#d_test_info").show();
        var _l="url(@(Url.Content("~/content/themes/default/images/loading.gif")))",
        _f="url(@(Url.Content("~/content/themes/default/images/icon_delete.png")))",
        _p="url(@(Url.Content("~/content/themes/default/images/icon_accept.png")))";

        var loader= $("#d_test_info").children(".d-loader");
        loader.css({"background-image":_l});
         $("#d_info").text("@Html.Global("SMTP_Sending_Test")");

        $.post("@Url.Action("TestSmtp")", function (_pass) {
            $("#d_buttons").show();
            if (_pass)
            {
               $("#d_info").text("@Html.Global("SMTP_Test_Pass")");
               loader.css({"background-image":_p});
            }
            else
            {
                $("#d_info").text("@Html.Global("SMTP_Test_Fail")");
                loader.css({"background-image":_f});
            }
        });
    }
</script>
